package com.zc.utils.redisThread;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RedisThread implements Runnable {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    private static RedisThread redisThread;
    private String content;

    public void setContent(String content) {
        this.content = content;
    }

    @Override
    public void run() {
               for (int i = 0;i<30;i++)
                    logger.debug(String.format("thread" + Thread.currentThread().getName() + "开始接收publish的消息::"+ content + "当前的时间是::"+System.currentTimeMillis()));
    }
    //避免线程的重复启用,使用单例模式
    //1.构造器私有化
    private RedisThread() {
    }
    //2.new 好单例供调用
    private static RedisThread instance(){
        redisThread = new RedisThread();
        Thread.currentThread().setName("redisPublish");
        return redisThread;
    }
    //提供公有方法供外部调用
    public static RedisThread getInstance(){
        if(redisThread == null){
            instance();
        }
        return redisThread;
    }

}
